#include "Commodity.h"
#include <string>
#include <iostream>
#include <stdlib.h>
#include <ctime>

using namespace std;

Commodity::Commodity(void)
{

}

Commodity::Commodity(string commodity_name, float global_base_price)
{

	//cout << "COM NAME: " << commodity_name << "  -   BASE PRICE: " << global_base_price << endl;
	name = commodity_name;
	price_global = global_base_price;
	price_current = price_global;
	init_bounds();
	generate_price();
}

void Commodity::init_bounds(void)
{
	int rand_int;
	int swing_mod_min = 30;
	int swing_mod_max = 100;
	
	rand_int = rand() % swing_mod_min + 1;
	//cout << "rand_int_min " << rand_int  << endl;
	swing_min = 1 - (float)rand_int/100;
	//cout << "swing_min " << swing_min << endl;
	
	rand_int = rand() % swing_mod_max + 1;
	//cout << "rand_int_max " << rand_int  << endl;
	swing_max = 1.0 + (float)rand_int/100;
	//cout << "swing_max " << swing_max << endl;
}

void Commodity::generate_price(void)
{
	float multiplier = random_float(swing_min, swing_max);
	price_current = price_global * multiplier;
}
	

float Commodity::random_float(float min, float max) {
    float random = ((float) rand()) / (float) RAND_MAX;
    float diff = max - min;
    float r = random * diff;
    return min + r;
}

Commodity::~Commodity(void)
{
}
